import { defineStore } from "pinia";
import { ref } from "vue";
import { getCurrentUserServer } from "@/api/user";

export const useLoginUserStore = defineStore("loginUser", () => {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  const loginUser = ref<any>({
    username: "未登录",
  });

  /**
   * 远程获取用户登录信息
   */
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  const fetchLoginUser = async () => {
    const res = await getCurrentUserServer();
    if (res.data.code === 0 && res.data.data) {
      loginUser.value = res.data.data;
    }
  };
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  const setLoginUser = (newLoginUser: any) => {
    loginUser.value = newLoginUser;
  };
  return { loginUser, fetchLoginUser, setLoginUser };
});
